package org.jeecg.modules.zhima.portal.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.modules.zhima.base.common.Result;
import org.jeecg.modules.zhima.center.entity.CmsSubject;
import org.jeecg.modules.zhima.center.entity.PmsProduct;
import org.jeecg.modules.zhima.center.entity.PmsProductCategory;
import org.jeecg.modules.zhima.portal.domain.HomeContentResult;
import org.jeecg.modules.zhima.portal.service.IShoppingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 首页内容管理Controller
 * Created by dingzg on 2019/1/28.
 */
@Controller
@Api(tags = "HomeController", description = "首页内容管理")
@RequestMapping("/shopping")
public class MShoppingController {

    @Autowired
    private IShoppingService shoppingService;


    @ApiOperation("首页内容页信息展示")
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    @ResponseBody
    public Result<?> content() {
        HomeContentResult contentResult = shoppingService.content();
        return Result.ok(contentResult);
    }

    @ApiOperation("分页获取推荐商品")
    @RequestMapping(value = "/recommendProductList", method = RequestMethod.GET)
    @ResponseBody
    public Result<?> recommendProductList(@RequestParam(value = "pageSize", defaultValue = "4") Integer pageSize,
                                                               @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        List<PmsProduct> productList = shoppingService.recommendProductList(pageSize, pageNum);
        return Result.ok(productList);
    }

    @ApiOperation("获取首页商品分类")
    @RequestMapping(value = "/productCateList/{parentId}", method = RequestMethod.GET)
    @ResponseBody
    public Result<?> getProductCateList(@PathVariable Long parentId) {
        List<PmsProductCategory> productCategoryList = shoppingService.getProductCateList(parentId);
        return Result.ok(productCategoryList);
    }

    @ApiOperation("根据分类获取专题")
    @RequestMapping(value = "/subjectList", method = RequestMethod.GET)
    @ResponseBody
    public Result<?> getSubjectList(@RequestParam(required = false) Long cateId,
                                                         @RequestParam(value = "pageSize", defaultValue = "4") Integer pageSize,
                                                         @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        List<CmsSubject> subjectList = shoppingService.getSubjectList(cateId,pageSize,pageNum);
        return Result.ok(subjectList);
    }

    @ApiOperation("分页获取人气推荐商品")
    @RequestMapping(value = "/hotProductList", method = RequestMethod.GET)
    @ResponseBody
    public Result<?> hotProductList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                         @RequestParam(value = "pageSize", defaultValue = "6") Integer pageSize) {
        List<PmsProduct> productList = shoppingService.hotProductList(pageNum,pageSize);
        return Result.ok(productList);
    }

    @ApiOperation("分页获取新品推荐商品")
    @RequestMapping(value = "/newProductList", method = RequestMethod.GET)
    @ResponseBody
    public Result<?> newProductList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                         @RequestParam(value = "pageSize", defaultValue = "6") Integer pageSize) {
        List<PmsProduct> productList = shoppingService.newProductList(pageNum,pageSize);
        return Result.ok(productList);
    }
}
